-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type.Is Nullable Type Rule Clarification #200
base: main
Are you sure you want to change the base?
Conversation
@bgribaudo : Thanks for your contribution! The author(s) have been notified to review your proposed change. |
Learn Build status updates of commit 30d1f95: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
Can you review the proposed changes? When the changes are ready for publication, add a #label:"aq-pr-triaged" |
query-languages/m/type-is.md
Outdated
Determines if a value of `type1` is always compatible with `type2`. | ||
Determines if a value of `type1` is always compatible with `type2`. | ||
|
||
Parameter `type2` is expected to be a nullable primitive type. When this requirement is not met, this function's behavior is undefined and so should not be relied on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true. By passing a nullable primitive type as the second arg, you can use Type.Is to check for both the nullable and non-nullable version of that type. But that's just one use of the function.
Here's another way it can be used, which doesn't involve nullable types at all:
Type.Is(Int64.Type, type number)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ehrenMSFT,
Thanks for this feedback.
Here's another way it can be used, which doesn't involve nullable types at all:
Type.Is(Int64.Type, type number)
I'm puzzled. Isn't type number
a nullable primitive type (where nullable primitive type = all primitive types + their nullable counterparts)?
In the language spec, operators as
and is
are described as only accepting "nullable primitive types as their right operand," and Value.Is
's second argument is described as accepting "an arbitrary type value as its first and a nullable primitive type value as its second argument." Examples are given like Type.Is(type number, type text)
and 1 is number
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the spec. I'm just basing my comments on how things actually seem to work.
Type.IsNullable(type number) returns false. You'd have to say "type nullable number" to make it nullable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ehrenMSFT!
Just opened a PR raising the question of how to best address the "nullable primitive type" terminology used in the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ehrenMSFT, just edited this to reflect the terminology that #203 has moved to. Does this look good to you now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are you getting the limitation that the second type must be a primitive or nullable primitive type? I don't see any limitation like this in our code. The logic seems more involved than that.
For example, the following returns true, even though Int64.Type isn't a primitive type.
Type.Is(type number, Int64.Type)
To give other examples, this returns false:
Type.Is(type [a=number], type [a=number])
while this returns true:
let recordType = type [a=number] in Type.Is(recordType, recordType)
How does the info you added account for these examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ehrenMSFT!
Happy New Year!
Where are you getting the limitation that the second type must be a primitive or nullable primitive type? I don't see any limitation like this in our code. The logic seems more involved than that.
The spec mentions this limitation—https://learn.microsoft.com/en-us/powerquery-m/m-spec-types:
Compatibility between a given type and a nullable primitive type can be determined using the library function Type.Is, which accepts an arbitrary type value as its first and a nullable primitive type value as its second argument: [...] There is no support in M for determining compatibility of a given type with a custom type.
I'd assumed that the above quote from the spec is correct, and so assumed that if Type.Is
seems to work when its second argument is not a primitive type or a nullable primitive type, its behavior shouldn't be relied on.
If that is inaccurate, can you advise on what is allowed as the second argument? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for clarifying I think I understand now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you planning to also update m-spec-types to mention that both nullable and non-nullable primitive types are supported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bgribaudo, @ehrenMSFT - has this pull request reached a conclusion? Is it ready to be merged? |
My feedback above still applies. |
@DougKlopfenstein, thanks for checking up on this. This is blocked by #203. (That PR renames a term in the language spec which can then be used here to resolve @ehrenMSFT's feedback.) |
Learn Build status updates of commit a4eb363: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
Co-authored-by: Ehren <ehvonleh@microsoft.com>
Learn Build status updates of commit e23d11c: ✅ Validation status: passed
For more details, please refer to the build report. For any questions, please:
|
Per https://learn.microsoft.com/en-us/powerquery-m/m-spec-types#type-equivalence-and-compatibility, this function's second parameter should only ever be a nullable primitive type.
This PR adds details about this requirement to the function's docs.